import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import VueParticles from 'vue-particles'  
　　

Axios.defaults.baseURL = 'http://127.0.0.1:8888'  // 默认地址
import {
  Button,
  Layout,
  Icon,
  Input,
  Tooltip,
  Form,
  notification,
  Progress,
  Popover,
  Select,
  Row,
  Col,
  message,
  Menu,
  Avatar,
  Space,
  Table,
  Tag,
  Divider,
  Modal,
  Badge,
  Timeline,
  Steps,
  Popconfirm

} from 'ant-design-vue'

Vue.config.productionTip = false
Vue.use(Button)
Vue.use(Layout)
Vue.use(Icon)
Vue.use(Input)
Vue.use(Tooltip)
Vue.use(Form)
Vue.use(Progress)
Vue.use(Popover)
Vue.use(Select)
Vue.use(Row)
Vue.use(Col)
Vue.use(Menu)
Vue.use(Avatar)
Vue.use(Space)
Vue.use(Table)
Vue.use(Tag)
Vue.use(Divider)
Vue.use(Modal)
Vue.use(Badge)
Vue.use(Timeline)
Vue.use(Steps)
Vue.use(Popconfirm)



Vue.prototype.$notification = notification
Vue.prototype.$message = message
Vue.prototype.$axios = Axios
Vue.use(VueParticles)
Axios.interceptors.request.use(
  config => {
    let token = localStorage.getItem("Access-Token");
    if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
      config.headers.token = `${token}`;
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  });

router.beforeEach((to, from, next) => {
  NProgress.start()
  const token = localStorage.getItem('Access-Token')
  if (to.path === '/user/login') {
    if (token !== null) {
      next('/home')
    }
    next()
  } else {
    if (token !== null) {
      next()
    } else {
      next('/user/login')
    }
  }

})

router.afterEach(() => {
  NProgress.done()
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
